package com.example.asus.practice;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;

public class ImageSWITCHER extends AppCompatActivity {
    ImageSwitcher is;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_switcher);

        is = (ImageSwitcher) findViewById((R.id.image_switch));

        is.setOutAnimation(AnimationUtils.loadAnimation(ImageSWITCHER.this,android.R.anim.fade_out));//淡出动画
        is.setInAnimation(AnimationUtils.loadAnimation(ImageSWITCHER.this,android.R.anim.fade_in));//进入动画

        is.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                ImageView imageView = new ImageView(ImageSWITCHER.this);
                imageView.setImageResource(R.drawable.img1);
                return imageView;
            }
        });
        is.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ImageSwitcher)v).setImageResource(R.drawable.img4);
            }
        });
    }
}
